﻿using System;
using System.Collections.Generic;
using UFSoft.UBF.Business;
using UFSoft.UBF.Eventing;
using UFIDA.U9.QC.QCDocBE;
using UFIDA.U9.PR.PRBE;
using UFIDA.U9.CBO.QC.Enums;
using ufida.u9.ait.openapi;
using UFSoft.UBF.Util.DataAccess;
using UFIDA.U9.PR.PurchaseRequest;
using UFSoft.UBF.Util.Collections;
using UFIDA.U9.MO.MO;
using UFSoft.UBF.PL;




namespace UFIDA.U9.Cust.LS.PlugBE
{
    /// <summary>
    /// 爱发科
    /// 质检单
    /// 根据质检单行上的转工序字段 生成请购单
    /// </summary>
    class AFKQCDeleteExtend : IEventSubscriber
    {
        //配置XX.sub.xml文件放置到portal/bin下，dll文件放置到portal/ApplicationServer/Libs下
        public void Notify(params object[] args)
        {
            if (args != null && args.Length != 0 && args[0] is EntityEvent)
            {
                BusinessEntity.EntityKey key = ((EntityEvent)args[0]).EntityKey;
                QCDoc be = key.GetEntity() as QCDoc;// 质检单

                if (be == null)
                    return;
                foreach (var qcline in be.QCDocLines.DelLists)
                {
                    QCDocLine qcline1 = (QCDocLine)qcline;

                    PR.PurchaseRequest.PR prbe = PR.PurchaseRequest.PR.Finder.Find("DocNo='" + qcline1.DescFlexField.PrivateDescSeg2 + "'");
                    if (prbe != null)
                    {
                        throw new Exception($"已有下游请购单:[{qcline1.DescFlexField.PrivateDescSeg2}],请检查!");
                    }
                }
            }
        }
    }
}

